#include "TileFileReader.h"

TileFileReader::TileFileReader(){}
TileFileReader::~TileFileReader(){}
Tile* TileFileReader::GetTile(unsigned int tile_type){
    Tile * e = new Tile();
    //find the file based on the int type
    const unsigned int total_digits = 8;
    char entity_number_string[total_digits];
    for(int i = 0; i < total_digits; i++)
        entity_number_string[i] = '\0';
    sprintf(entity_number_string, "%d", tile_type);

    char path[MAX_PATH_LENGTH];

    for(int i = 0; i < MAX_PATH_LENGTH; i++)
        path[i] = '\0';

    strcat(path, TILE_DIRECTORY);
    strcat(path, entity_number_string);
    strcat(path, TILE_EXTENSION);	

    //open the file
    OpenFile(path);

    //tokenize the file
    TokenizeFile();

    //assign the fields to the entity
    for(unsigned int i = 0; i < GetTotalTokens(); i++){
        if(GetToken(i) == "x"){
            int int_value = atoi(GetToken(i+2).c_str());
            e->SetX(int_value);
        }
        if(GetToken(i) == "y"){
            int int_value = atoi(GetToken(i+2).c_str());
            e->SetY(int_value);
        }
    }


    //add the entity to the list
    //return the entity address 

	Entity::AddToEntityList(e);

    return (Tile*)e; 



}